package org.tea.inventory.db.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.tea.inventory.db.dao.FightingRecordMapper;
import org.tea.inventory.db.domain.FightingRecord;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 凌风
 * @date 2019-04-26 17:10
 */
@Service
public class FightingRecordService {

    @Resource
    private FightingRecordMapper fightingRecordMapper;

    public int insertSelective(FightingRecord fightingRecord){
        return fightingRecordMapper.insertSelective(fightingRecord);
    }

    public Map<String,Object> selectFightingRecordByOpenId(String openId,Integer page,Integer size){
        PageHelper.startPage(page, size);
        List list = fightingRecordMapper.selectFightingRecordByOpenId(openId);
        PageInfo pageinfo = new PageInfo(list);
        Map<String,Object> resMap = new HashMap<String,Object>();
        resMap.put("pageNum",pageinfo.getPageNum());
        resMap.put("pageSize", pageinfo.getPageSize());
        resMap.put("startRow", pageinfo.getStartRow());
        resMap.put("endRow", pageinfo.getEndRow());
        resMap.put("total", pageinfo.getTotal());
        resMap.put("pages", pageinfo.getPages());
        resMap.put("items", list);
        return resMap;
    }

}
